package com.meizu.asum.richtextsdk.tools.selectpictools.tools;

import android.app.Activity;
import android.database.Cursor;
import android.net.Uri;
import android.provider.MediaStore;

import java.io.File;

/**
 * Uri相关工具类
 *
 * @Author XJW
 * @CreateTime 2017/6/5
 */
public class UriTools {
    public static Uri getFileUriFromMediaUri(Activity activity, Uri uri) {
        if (uri == null) {
            return uri;
        }

        String[] proj = {MediaStore.Images.Media.DATA};
        Cursor actualimagecursor = activity.getContentResolver().query(uri, proj, null, null, null);
        int actual_image_column_index = actualimagecursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
        actualimagecursor.moveToFirst();
        String img_path = actualimagecursor.getString(actual_image_column_index);
        File file = new File(img_path);
        return Uri.fromFile(file);
    }
}
